package com.taijihuabao.common.approveprocess;

import com.taijihuabao.modules.service.ApprovalProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *策略工厂
 * @author xuejingtai
 */
@Component
public class ApproveProcessFactory {
    /**
     * 创建线程安全的map,存放具体审批流程key，及策略实体对象
     */

    public static Map<String, ApprovalProcessService> approveProcess = new ConcurrentHashMap<>();

    /**
     * 在注入容器的时候，自动把ApprovalProcessService类下的实例给传到map中
     * @param approvalProcessServiceList
     */
    @Autowired
    public void getApprovalProcessService(@Autowired List<ApprovalProcessService> approvalProcessServiceList){
        for(ApprovalProcessService approvalProcess:approvalProcessServiceList) {
            approveProcess.put(approvalProcess.getProcessName(), approvalProcess);
        }
    }

    /**
     * 根据传入的审批流程名称，获取对应的审批流程对象
     * @param processName
     * @return
     */
    public ApprovalProcessService getApprovalProcessServiceImpl(String processName){
        return approveProcess.get(processName);
    }

}
